package au.edu.swin.MelbourneMap;
 
import java.awt.Graphics2D;
import java.awt.geom.NoninvertibleTransformException;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.io.File;
import java.util.ArrayList;

import javax.swing.JInternalFrame;
import javax.swing.WindowConstants;
 
/* Used by InternalFrameDemo.java. */
public class MyInternalFrame extends JInternalFrame
{
	
    static int openFrameCount = 0;
    static final int xOffset = 330, yOffset = 240;
    
    private MapPanel mappingPanel;
    private Model innerModel = new Model();
    private Model outerModel;
    private ArrayList<Point2D> rect = new ArrayList<Point2D>();
    private Path2D path;
 
    public MyInternalFrame(Model model)
        throws NoninvertibleTransformException
    {
        super(
            "Document #" + (++openFrameCount),
            true,  // resizable
            true,  // closable
            true,  // maximizable
            true); // iconifiable
 
        
		// ...Create the GUI and put it in the window...
        try
        {
        	
        	File filePath = new File("./data");
        	System.out.println(filePath.getCanonicalPath());
        	this.setDefaultCloseOperation(
                    WindowConstants.HIDE_ON_CLOSE);
            outerModel = model;
			innerModel.readFile(filePath.getCanonicalPath()+"/Victoria2.txt");//"/Users/Dotke/Documents/workspaceJava/ADJ22/data/Victoria2.txt");
	        mappingPanel = new MapPanel( innerModel,300,210 );
	        innerModel.resetScale();
	        this.setPath( outerModel.getRectangle() );
	        
	        mappingPanel.redraw();
	        this.add( mappingPanel );
	        
	        mappingPanel.setVisible( true );
	        mappingPanel.setBounds( 0, 0, 300, 215 );
            
	        // ...Then set the window size or call pack...
	        setSize( 350, 275 );
	 
	        //Set the window's location.
	        setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
	    }
        catch( Exception ex )
        {
            System.out.println( "ERR: " + ex.getCause() );
        }
    }
    
    public void drawRect()
    {
    	if(path!=null)
    		mappingPanel.drawRectangle(path);
    	
    }
	public void setRect(ArrayList<Point2D> rect) {
		this.rect = rect;
		 for(Point2D p : rect)
	        	System.out.println("p: "+p);
	       
	}

	public ArrayList<Point2D> getRect() {
		return rect;
	}

	public void setPath(Path2D path) {
		this.path = path;
	}

	public Path2D getPath() {
		return path;
	}
    }